<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('账户间往来列表')" />
</head>
<body class="gray-bg">
     <div class="container-div">
        <div class="row">
            <div class="col-sm-12 search-collapse">
                <form id="formId">
                    <div class="select-list">
                        <ul>
                            <li>
                                <label>流入账户：</label>
                                <select name="inAccount" th:with="type=${@customDictService.selectDictBanks()}">
                                    <option value="">所有</option>
                                    <option value="0">无</option>
                                    <option th:each="dict : ${type}" th:text="${dict.name}" th:value="${dict.id}"></option>
                                </select>
                            </li>
                            <li>
                                <label>流出账户：</label>
                                <select name="outAccount" th:with="type=${@customDictService.selectDictBanks()}">
                                    <option value="">所有</option>
                                    <option value="0">无</option>
                                    <option th:each="dict : ${type}" th:text="${dict.name}" th:value="${dict.id}"></option>
                                </select>
                            </li>
                            <li>
                                <label>金额：</label>
                                <input type="text" name="amount"/>
                            </li>
                            <li>
                                <label>日期：</label>
                                <input type="text" class="time-input" placeholder="开始日期" style="width: 100px" name="params[beginTime]"/>
                                <sapn> - </sapn>
                                <input type="text" class="time-input" placeholder="开始日期" style="width: 100px" name="params[endTime]"/>
                            </li>
                            <li>
                                <label>状态：</label>
                                <select name="status" th:with="type=${@dict.getType('delete_flag')}">
                                    <option value="">所有</option>
                                    <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}" th:selected="${dict.dictValue == '0'}"></option>
                                </select>
                            </li>
                            <li>
                                <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i class="fa fa-search"></i>&nbsp;搜索</a>
                                <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i class="fa fa-refresh"></i>&nbsp;重置</a>
                            </li>
                        </ul>
                    </div>
                </form>
            </div>

            <div class="btn-group-sm" id="toolbar" role="group">
                <a class="btn btn-success" onclick="$.operate.add()" shiro:hasPermission="erp:transfer:add">
                    <i class="fa fa-plus"></i> 添加
                </a>
            </div>
            <div class="col-sm-12 select-table table-striped">
                <table id="bootstrap-table"></table>
            </div>
        </div>
    </div>
    <th:block th:include="include :: footer" />
    <script th:inline="javascript">
        var editFlag = [[${@permission.hasPermi('erp:bank:transfer:edit')}]];
        var removeFlag = [[${@permission.hasPermi('erp:bank:transfer:remove')}]];
        var statusDatas = [[${@dict.getType('delete_flag')}]];
        var bankDatas = [[${@customDictService.selectDictBanks()}]];
        var prefix = ctx + "erp/transfer";

        $(function() {
            var options = {
                url: prefix + "/list",
                createUrl: prefix + "/add",
                updateUrl: prefix + "/edit/{id}",
                removeUrl: prefix + "/remove",
                exportUrl: prefix + "/export",
                modalName: "账户间往来",
                sortOrder: "Desc",
                sortName: "payDate",
                columns: [
                {
                    field: 'id',
                    title: '',
                    visible: false
                },
                {
                    field: 'inAccount',
                    title: '流入账户',
                    formatter: function(value, row, index) {
                        return displayBankName(bankDatas, value);
                    }
                },
                {
                    field: 'outAccount',
                    title: '流出账户',
                    formatter: function(value, row, index) {
                        return displayBankName(bankDatas, value);
                    }
                },
                {
                    field: 'amount',
                    title: '金额'
                },
                {
                    field: 'payDate',
                    title: '日期'
                },
                {
                    field: 'remark',
                    title: '备注'
                },
                {
                    field: 'createBy',
                    title: '登记人'
                },
                {
                    field: 'createTime',
                    title: '登记时间'
                },
                {
                    field: 'status',
                    title: '状态',
                    formatter: function(value, row, index) {
                       return $.table.selectDictLabel(statusDatas, value);
                    }
                },
                {
                    title: '操作',
                    align: 'center',
                    formatter: function(value, row, index) {
                        var actions = [];
                        actions.push('<a class="btn btn-success btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="$.operate.edit(\'' + row.id + '\')"><i class="fa fa-edit"></i>编辑</a> ');
                        actions.push('<a class="btn btn-danger btn-xs ' + removeFlag + '" href="javascript:void(0)" onclick="$.operate.remove(\'' + row.id + '\')"><i class="fa fa-remove"></i>删除</a>');
                        return actions.join('');
                    }
                }]
            };
            $.table.init(options);
        });

        function displayBankName(datas, bankId)
        {
            if (bankId == '0') return '<span>无</span>';
            var actions = [];
            $.each(datas, function(index, dict) {
                if (dict.id == ('' + bankId)) {
                    var listClass = $.common.equals("default", dict.listClass) || $.common.isEmpty(dict.listClass) ? "" : "badge badge-" + dict.listClass;
                    actions.push($.common.sprintf("<span class='%s'>%s</span>", listClass, dict.name));
                    return false;
                }
            });
            if (actions.length === 0) {
                actions.push($.common.sprintf("<span>%s</span>", bankId))
            }
            return actions.join('');
        }
    </script>
</body>
</html>